home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ADA Programming Guide
/
ADA Programming Guide.iso
/
adatutor
/
lrmrdr
/
stats.a
< prev
next >
Wrap
Text File
|
1996-01-30
|
6KB
|
175 lines
-- Stats by Richard Conn
-- Scan Ada LRM Chapter Files and generate information on their
-- attributes, sending the results to standard output.
-- Stats is a part of the Ada LRM Reader.
-- ***********************************************************************
-- ON-LINE Ada LANGUAGE REFERENCE MANUAL by Richard Conn
--
-- COPYRIGHT NOTICE
-- Ada LRM Reader - Interactive Presentation of the Ada LRM
-- Copyright (C) 1992 Richard Conn
--
-- This program is free software; you can redistribute it
-- and/or modify it under the terms of the GNU General Public
-- License Version 1 as published by the Free Software
-- Foundation.
--
-- This program is distributed in the hope that it will be
-- useful, but WITHOUT ANY WARRANTY; without even the implied
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-- PURPOSE. See the GNU General Public License for more
-- details. You should have received a copy of the GNU General
-- Public License along with this program; if not, write to the
-- Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
-- 02139, USA. See the ABOUT screens for further information,
-- including information on how to contact the author.
with Console; -- CS Parts
with Input_File; -- CS Parts
procedure Stats is
subtype FN_STRING is STRING(1..10);
type FN_VECTOR is array (NATURAL range <>) of FN_STRING;
File_Names : constant FN_VECTOR := (
"chap01.doc", "chap02.doc", "chap03.doc", "chap04.doc",
"chap05.doc", "chap06.doc", "chap07.doc", "chap08.doc",
"chap09.doc", "chap10.doc", "chap11.doc", "chap12.doc",
"chap13.doc", "chap14.doc", "chapaa.doc", "chapab.doc",
"chapac.doc", "chapad.doc", "chapae.doc", "chapaf.doc",
"chapco.doc", "chapfo.doc", "chapin.doc", "chappo.doc",
"chaphe.doc", "chapxx.doc"
);
Input_File_ID : Input_File.FILE_TYPE;
Max_Input_Line_Length : constant := 200;
Inline : STRING (1..Max_Input_Line_Length);
Inlast : NATURAL;
Start : NATURAL;
Stop : NATURAL;
Global_Largest_Number_of_Sections : NATURAL := 0;
Global_Longest_Line : NATURAL := 0;
Global_Longest_Section : NATURAL := 0;
Global_Line_Number : NATURAL := 0;
File_Number : NATURAL := 0;
Total_Number_of_Sections : NATURAL := 0;
Total_Number_of_Lines : NATURAL := 0;
----------------------------------------------------------------
-- Generate statistics on a particular file.
procedure Process_File (Name : in STRING) is
Lines_per_Section : NATURAL := 0;
Longest_Section : NATURAL := 0;
Longest_Line : NATURAL := 0;
Line_Number : NATURAL := 0;
Number_of_Sections : NATURAL := 0;
begin
Input_File.Open (Input_File_ID, Name);
File_Number := File_Number + 1;
-- Pass over file, collecting statistics
while not Input_File.End_of_File (Input_File_ID) loop
Input_File.Get_Line (Input_File_ID, Inline, Inlast);
if Inlast > Longest_Line then
Longest_Line := Inlast;
end if;
Line_Number := Line_Number + 1;
Lines_per_Section := Lines_per_Section + 1;
if Inlast > 2 and then Inline(1..2) = "> " then
Number_of_Sections := Number_of_Sections + 1;
Lines_per_Section := Lines_per_Section - 1;
if Lines_per_Section > Global_Longest_Section then
Global_Longest_Section := Lines_per_Section;
end if;
if Lines_per_Section > Longest_Section then
Longest_Section := Lines_per_Section;
end if;
Lines_per_Section := 1;
end if;
end loop;
-- Update the global data on the longest items
if Longest_Line > Global_Longest_Line then
Global_Longest_Line := Longest_Line;
end if;
if Lines_per_Section > Global_Longest_Section then
Global_Longest_Section := Lines_per_Section;
end if;
if Lines_per_Section > Longest_Section then
Longest_Section := Lines_per_Section;
end if;
if Line_Number > Global_Line_Number then
Global_Line_Number := Line_Number;
end if;
if Number_of_Sections > Global_Largest_Number_of_Sections then
Global_Largest_Number_of_Sections := Number_of_Sections;
end if;
-- Update the global data on the totals
Total_Number_of_Sections := Total_Number_of_Sections +
Number_of_Sections;
Total_Number_of_Lines := Total_Number_of_Lines +
Line_Number;
Input_File.Close (Input_File_ID);
-- Display data accumulated for the current file
Console.Put (File_Number, 2);
Console.Put (". " & Name);
Console.Put (Line_Number, 6);
Console.Put (Number_of_Sections, 6);
Console.Put (Longest_Section, 6);
Console.Put (Longest_Line, 6);
Console.New_Line;
exception
when others =>
Console.Put_Line ("Error on File " & Name);
end Process_File;
procedure Print_Header (First_Header : in STRING) is
begin
Console.Put (First_Header);
Console.Put (" Lines");
Console.Put (" Sects");
Console.Put (" Slen");
Console.Put (" LLen");
Console.New_Line;
end Print_Header;
begin -- Make_CIT
Print_Header (" File Name ");
-- Build chapters.idx file
for I in File_Names'RANGE loop
Process_File (File_Names(I));
end loop;
Console.New_Line;
Print_Header (" ");
-- Display data on the longest/largest values
Console.Put ("Longest => ");
Console.Put (Global_Line_Number, 6);
Console.Put (Global_Largest_Number_of_Sections, 6);
Console.Put (Global_Longest_Section, 6);
Console.Put (Global_Longest_Line, 6);
Console.New_Line;
-- Display data on the totals
Console.New_Line;
Console.Put ("Total Lines =>");
Console.Put (Total_Number_of_Lines, 6);
Console.New_Line;
Console.Put ("Total Sections =>");
Console.Put (Total_Number_of_Sections, 6);
Console.New_Line;
end Stats;